home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-02-27 | 7.3 KB | 243 lines | [TEXT/PJMM] |
- { CDEFUtils }
- {}
- { Miscellaneous utility constants & routines for the CDEFs }
- {}
- { Copyright © Sebastiano Pilla 1996 }
- { All rights reserved }
-
- { <mailto:case@tvol.it> }
-
- unit CDEFUtils;
-
-
- interface
-
-
- uses
- QDOffscreen, Controls;
-
-
- const
- kClearHighByteMask = $80000000; { For masking out the high bit of inParam on 24-bit addressing }
-
- kBlackPatternIndex = 1; { Index of standard black pattern into sysPatListID }
- kWhitePatternIndex = 20; { Index of standard white pattern into sysPatListID}
- kGrayPatternIndex = 4; { Index of 50% black-50% white pattern into sysPatListID }
-
- kBlackColorRGBComp = $0000; { R, G, B components of the black color }
- kWhiteColorRGBComp = $FFFF; { R, G, B components of the white color }
- kDarkGrayColorRGBComp = $4000; { R, G, B components of the dark gray color }
- kSteelBlueColorRGComp = $CCCC; { R, G components of the steel blue color }
- kSteelBlueColorBComp = $FFFF; { B component of the steel blue color }
- kDimGrayColorRGBComp = $7FFF; { R, G, B components of the gray color used in dimming }
- kChiselGrayColorRGBComp = $AAAA; { R, G, B components of the gray color for the chisel effect (develop 15) }
- kLightGrayRGBComp = $EEEE; { R, G, B components of the light gray color (develop 15) }
- kOpColorRGBComp = $8000; { R, G, B components of the color used in addPin, ecc. modes }
-
- kBlackAndWhiteDepth = 1; { Depth of a black&white port, in bits per pixel }
- kDeepestDeviceDepth = 0; { To use the depth of the deepest device in NewGWorld }
-
- kOffWorldFlags = 0; { Flags passed to NewGWorld }
-
- kColorGrafPortMask = $C000; { Mask applied to portVersion to check for a color port }
-
-
- { SetRGBColor }
- {}
- { Sets the components of a RGBColor to the given values }
- {}
- { Entry: inRedComp = desired red component }
- { inGreenComp = desired green component }
- { inBlueComp = desired blue component }
- { Exit: outColor = RGB color with the specified component values }
- procedure SetRGBColor (var outColor: RGBColor;
- inRedComp, inGreenComp, inBlueComp: UInt16);
-
-
- { SetRGBForeColor }
- {}
- { Sets the components of the foreground color }
- {}
- { Entry: inRedComp = desired red component }
- { inGreenComp = desired green component }
- { inBlueComp = desired blue component }
- procedure SetRGBForeColor (inRedComp, inGreenComp, inBlueComp: UInt16);
-
-
- { SetRGBBackColor }
- {}
- { Sets the components of the background color }
- {}
- { Entry: inRedComp = desired red component }
- { inGreenComp = desired green component }
- { inBlueComp = desired blue component }
- procedure SetRGBBackColor (inRedComp, inGreenComp, inBlueComp: UInt16);
-
-
- { SetRGBOpColor }
- {}
- { Sets the components for the color used in addPin, ... modes }
- {}
- { Entry: inRedComp = desired red component }
- { inGreenComp = desired green component }
- { inBlueComp = desired blue component }
- procedure SetRGBOpColor (inRedComp, inGreenComp, inBlueComp: UInt16);
-
-
- { EqualRGBColorComponents }
- {}
- { Checks if all the 3 components of a color match the given value }
- {}
- { Entry: inColor = color to check }
- { inComponent = value to check }
- { Exit: function result = TRUE if all the 3 color components match the given component, FALSE if at least one }
- { component is different }
- function EqualRGBColorComponents (inColor: RGBColor;
- inComponent: UInt16): Boolean;
-
-
- { GetControlPortDepth }
- {}
- { Returns the depth of the port owning the specified control }
- {}
- { Entry: inControlHdl = handle to control }
- { Exit: function result = depth of port owning the given control }
- function GetControlPortDepth (inControlHdl: ControlHandle): UInt16;
-
-
- { CreateControlOffscreenWorld }
- {}
- { Creates and sets up an offscreen graphics world to optimize the drawing of the given control }
- {}
- { Entry: inControlHdl = handle to control (necessary for contrlRect and contrlOwner) }
- { Exit: outOffscreenWorldPtr = pointer to offscreen world (or NIL if errors) }
- { function result = error code }
- function CreateControlOffscreenWorld (inControlHdl: ControlHandle;
- var outOffscreenWorldPtr: GWorldPtr): OSErr;
-
-
- implementation
-
-
- procedure SetRGBColor (var outColor: RGBColor;
- inRedComp, inGreenComp, inBlueComp: UInt16);
- begin
- with outColor do
- begin
- red := inRedComp;
- green := inGreenComp;
- blue := inBlueComp;
- end;
- end;
-
-
- procedure SetRGBForeColor (inRedComp, inGreenComp, inBlueComp: UInt16);
- var
- theForeColor: RGBColor;
- begin
- with theForeColor do
- begin
- red := inRedComp;
- green := inGreenComp;
- blue := inBlueComp;
- end;
- RGBForeColor(theForeColor);
- end;
-
-
- procedure SetRGBBackColor (inRedComp, inGreenComp, inBlueComp: UInt16);
- var
- theBackColor: RGBColor;
- begin
- with theBackColor do
- begin
- red := inRedComp;
- green := inGreenComp;
- blue := inBlueComp;
- end;
- RGBBackColor(theBackColor);
- end;
-
-
- procedure SetRGBOpColor (inRedComp, inGreenComp, inBlueComp: UInt16);
- var
- theOpColor: RGBColor;
- begin
- with theOpColor do
- begin
- red := inRedComp;
- green := inGreenComp;
- blue := inBlueComp;
- end;
- OpColor(theOpColor);
- end;
-
-
- function EqualRGBColorComponents (inColor: RGBColor;
- inComponent: UInt16): Boolean;
- begin
- with inColor do
- EqualRGBColorComponents := (red = inComponent) & (green = inComponent) & (blue = inComponent);
- end;
-
-
- function GetControlPortDepth (inControlHdl: ControlHandle): UInt16;
- begin
- if BAND(CGrafPtr(inControlHdl^^.contrlOwner)^.portVersion, kColorGrafPortMask) <> 0 then
- GetControlPortDepth := CGrafPtr(inControlHdl^^.contrlOwner)^.portPixMap^^.pixelSize
- else
- GetControlPortDepth := kBlackAndWhiteDepth;
- end;
-
-
- function CreateControlOffscreenWorld (inControlHdl: ControlHandle;
- var outOffscreenWorldPtr: GWorldPtr): OSErr;
- var
- controlBounds: Rect;
- savePort: CGrafPtr;
- saveDevice: GDHandle;
- offPMapHdl: PixMapHandle;
- err: OSErr;
- begin
-
- { Save current port and device }
- GetGWorld(savePort, saveDevice);
-
- { Get the control's rectangle: this will become the offscreen world's boundary rectangle }
- controlBounds := inControlHdl^^.contrlRect;
-
- { Create an offscreen world optimized for CopyBits speed by using the depth of the deepest screen }
- { intersecting the control's rectangle }
- err := NewGWorld(outOffscreenWorldPtr, kDeepestDeviceDepth, controlBounds, nil, nil, kOffWorldFlags);
- if err = noErr then
- begin
- SetGWorld(outOffscreenWorldPtr, nil);
-
- { Move the offscreen world coordinate system to the topLeft corner of the control's rectangle, or all our }
- { future drawing will be in the wrong position! }
- SetOrigin(controlBounds.left, controlBounds.top);
-
- { Make sure we don't draw outside our GWorld }
- ClipRect(outOffscreenWorldPtr^.portRect);
-
- { Get the GWorld's pixMap and lock it to draw safely }
- offPMapHdl := GetGWorldPixMap(outOffscreenWorldPtr);
- if LockPixels(offPMapHdl) then
- begin
-
- { Set the default colors, erase the offscreen world and unlock its pixMap }
- SetRGBForeColor(kBlackColorRGBComp, kBlackColorRGBComp, kBlackColorRGBComp);
- SetRGBBackColor(kWhiteColorRGBComp, kWhiteColorRGBComp, kWhiteColorRGBComp);
- SetRGBOpColor(kOpColorRGBComp, kOpColorRGBComp, kOpColorRGBComp);
- EraseRect(outOffscreenWorldPtr^.portRect);
- UnlockPixels(offPMapHdl);
- end;
- end;
-
- { Restore previously saved port and device }
- SetGWorld(savePort, saveDevice);
- CreateControlOffscreenWorld := err;
- end;
-
-
- end.